//
// Created by daiyizheng on 2022/4/12.
//
#include <vector>
#include <algorithm>
using namespace std;

class Solution {
public:
    //完全背包问题
    int numSquares(int n) {
        //定义维度
        vector<int> dp(n+1, INT_MAX);
        //初始化
        dp[0] = 0;

        for (int i = 1; i <= sqrt(n); ++i) {
            for (int c = i*i; c <=n ; c++) {
                dp[c] = min(dp[c], dp[c-i*i]+1);
            }
        }
        return dp[n];
    }
};